<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--[if lt IE 9]>
            <script type="text/javascript" src="lib/html5shiv.js"></script>
            <script type="text/javascript" src="lib/respond.min.js"></script>
            <![endif]-->
    <link rel="stylesheet" type="text/css" href="../static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="../lib/Hui-iconfont/1.0.8/iconfont.css" />

    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/style.css" />
    <link rel="stylesheet" href="./../lib/layui/css/layui.css">
    <!--[if IE 6]>
            <script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
            <script>DD_belatedPNG.fix('*');</script>
            <![endif]-->
</head>

<body>
    <div class="page-container">
            <div class="row cl" style = "margin-bottom:10px;">
                    <label class="form-label col-xs-4 col-sm-2">首页展示：</label>
                    <div class="formControls col-xs-8 col-sm-9">
                        <select  class="input-text" id="top" name="">
                            <option value="0">不展示</option>
                            <option value="1">展示</option>
                        </select>
                    </div>
                </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">分类名：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="" id="partition" name="">
            </div>
        </div>
        <div class="row cl"  style="margin-top:10px;">
            <label class="form-label col-xs-4 col-sm-2">排序：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="" id="sort" name="">
            </div>
        </div>
        <div class="row cl"  style="margin-top:10px;">
                <label class="form-label col-xs-4 col-sm-2">描述：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="" placeholder="" id="detail" name="">
                </div>
            </div>
        <div class="row cl" style="margin-top:10px;">
            <label class="form-label col-xs-4 col-sm-2">背景图：</label>
            <div class="layui-upload formControls col-xs-8 col-sm-9">
                <button type="button" class="layui-btn" id="uploadPicture">上传图片</button>
                <div class="layui-upload-list">
                    <div style="width:150px;height: 150px;display: none" id="pictureBox">
                        <img class="layui-upload-img" id="picture" style="width:auto;height:100%;">

                    </div>
                    <p id="demoText" style="margin-top:5px"></p>
                </div>
            </div>
            <div class="row cl">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2" style="margin-bottom:20px;margin-top:10px">
                    <div onClick="save_submit();" class="btn btn-primary radius" id="save">保存</div>
                    <button onClick="layer_close();" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
                </div>
            </div>
        </div>
        <script type="text/javascript" src="../lib/jquery/1.9.1/jquery.min.js"></script>
        <script type="text/javascript" src="./../static/js/common.js"></script>
        <script type="text/javascript" src="../lib/layer/2.4/layer.js"></script>
        <script type="text/javascript" src="../static/h-ui/js/H-ui.min.js"></script>
        <script type="text/javascript" src="../static/h-ui.admin/js/H-ui.admin.js"></script>
        <script type="text/javascript" src="./../lib/layui/layui.js"></script>
        <script>
            var img = '';
            layui.use('upload', function () {
                var upload = layui.upload;
                // 单个图片上传
                var uploadInst = upload.render({
                    elem: '#uploadPicture',
                    url: admin_url + '/uf/uploadFile',
                    accept: 'images',
                    before: function (obj) {

                        //预读本地文件，不支持ie8
                        obj.preview(function (index, file, result) {
                            $("#pictureBox").css("display", "block");
                            $('#picture').attr('src', result); //图片链接（base64）
                        });
                    },
                    done: function (res) {
                        // 赋值图片网路路劲
                        img = res.data.src
                   
                        if (res.code != 0) {
                            return layer.msg('上传失败');
                        }
                    },
                    error: function () {
                        var demoText = $('#demoText');
                        demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                        demoText.find('.demo-reload').on('click', function () {
                            uploadInst.upload();
                        });
                    }
                })
            })
            function save_submit() {
                var partition = $("#partition").val(),
                    sort = $("#sort").val(),
                    detail =$("#detail").val();
                $.ajax({
                    type: "post",
                    xhrFields: { withCredentials: true },
                    url: admin_url + '/kvmProductPartition/addProductPartition',
                    data: { tokenUserId: userId, token: token, name: partition,des:detail,sort:sort,backGroundImg:img,top:$("#top option:selected").val() },
                    success: function (data) {
                        layer.msg("添加成功", {
                            time: 1000,
                            end: function () {
                                var index = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(index);
                                    // window.parent.location.reload();
                                    $(window.parent.document).find('.layui-laypage-btn').click()
                            }
                        })
                    }
                })
            }

        </script>
</body>

</html>